var express = require('express');
var router = express.Router();
var stuModel=require('../database/model/stuModel.js')
/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

router.post('/stu', function(req, res, next) {//录入学员 
  let {name,score}=req.body
   new stuModel({
     name,
     score
   }).save().then(result=>{
    res.send({
      code:1,
      msg:'新增成功'
    })
   })
});
router.delete('/stu', function(req, res, next) {
   console.log(req.query); 
   let {id}=req.query
   stuModel.remove({_id:id}).then(result=>{
     res.send({
      code:1,
      msg:'删除成功'
     })
   })
});
router.put('/stu', function(req, res, next) {
  console.log(req.query); 
  console.log(res.body); 

  // let {id}=req.query
  stuModel.updateOne(req.query,req.body).then(result=>{
    res.send({
     code:1,
     msg:'修改成功'
    })
  })
});
router.get('/stu', function(req, res, next) {
  console.log(req.query); 
  console.log(res.body); 
  // let {id}=req.query
  stuModel.find().then(result=>{
    res.send({
     code:1,
     msg:'查询成功'
    })
  })
});
module.exports = router;
 